package com.sprouting.ops.controller;

import com.sprouting.ops.model.OpsSiteNetwork;
import com.sprouting.ops.model.ResultJson;
import com.sprouting.ops.model.bo.OpsSiteNetworkBo;
import com.sprouting.ops.service.OpsSiteNetworkService;
import com.sprouting.ops.utils.CheckTool;
import com.sprouting.ops.utils.EntityTool;
import com.sprouting.ops.utils.IdTool;
import org.springframework.web.bind.annotation.*;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sprouting.ops.annotations.invoke.IdempotentSingle;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.sprouting.ops.interfaces.AddGroup;
import com.sprouting.ops.interfaces.UpdGroup;

/**
 * 现场网络部署图(OpsSiteNetwork)(OPS_SITE_NETWORK) 表控制层
 *
 * @author ：lx（长沙麓谷）
 * @date 创建时间：2025-08-12 20:53:46
 */
@Slf4j
@RestController
@RequestMapping("opsSiteNetwork")
public class OpsSiteNetworkController {

    @Resource
    private OpsSiteNetworkService opsSiteNetworkService;


    /**
     * 根据现场id查询网络部署图，暂时只会一个现场只有一个
     * @param siteId 现场id
     * @return
     */
    @PostMapping("getBySiteId")
    public ResultJson getBySiteId(String siteId){
        if (CheckTool.checkNull(siteId)){
            return ResultJson.errorCheck();
        }
        return ResultJson.success(opsSiteNetworkService.getBySiteId(siteId));
    }

    /**
     * 删除现场网络部署图
     * @param id 现场网络部署图id
     * @return
     */
    @PostMapping("delOpsSiteNetwork")
    @IdempotentSingle
    public ResultJson delOpsSiteNetwork(String id){
        if (CheckTool.checkNull(id)){
            return ResultJson.errorCheck();
        }

        opsSiteNetworkService.removeById(id);
        return ResultJson.success();
    }

    /**
     * 更新现场网络部署图
     * @param bo 修改参数
     * @return
     */
    @PostMapping("updOpsSiteNetwork")
    @IdempotentSingle
    public ResultJson updOpsSiteNetwork(@Validated(UpdGroup.class) OpsSiteNetworkBo bo){
        String msg = checkOpsSiteNetwork(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        OpsSiteNetwork opsSiteNetwork = BeanUtil.copyProperties(bo, OpsSiteNetwork.class);

        EntityTool.updBase(opsSiteNetwork);
        opsSiteNetworkService.updateById(opsSiteNetwork);
        return ResultJson.success(bo);
    }

    /**
     * 保存现场网络部署图
     * @param bo 保存参数
     * @return
     */
    @PostMapping("saveOpsSiteNetwork")
    @IdempotentSingle
    public ResultJson saveOpsSiteNetwork(@Validated(AddGroup.class) OpsSiteNetworkBo bo){
        String msg = checkOpsSiteNetwork(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        OpsSiteNetwork opsSiteNetwork = BeanUtil.copyProperties(bo, OpsSiteNetwork.class);
        opsSiteNetwork.setId(IdTool.getId());
        opsSiteNetwork.setName("未命名");

        EntityTool.saveBase(opsSiteNetwork);
        opsSiteNetworkService.save(opsSiteNetwork);
        return ResultJson.success(bo);
    }


    /**
     * 现场网络部署图数据校验
     * @param bo 现场网络部署图 校验数据
     * @return 非null则有错误
     */
    private String checkOpsSiteNetwork(OpsSiteNetworkBo bo){

        return null;
    }

}
